package com.wang.sql.util

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}

import java.util.Properties

/**
 * @Desc kafka 生产者
 * @Author wang bo
 * @Date 2021/11/4 19:20
 */
object KafkaProduce {

  def sendMessage(list:List[String]): Unit ={
    val properties: Properties = new Properties()
    properties.put("bootstrap.servers", "devcdh1:9092,devcdh2:9092,devcdh3:9092")
    properties.put("group.id", "bigdata")
    properties.put("acks", "all")
    properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    val producer: KafkaProducer[String, String] = new KafkaProducer(properties)
    list.foreach(item=>{
      println(item)
      producer.send(new ProducerRecord[String, String]("flink_sql_1", item))
      Thread.sleep(10000)
    })
    producer.close()
  }

}
